package com.huawei.appgallery.forum.option.comment.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.common.media.api.IImagePreviewProtocol;
import com.huawei.appgallery.common.media.api.IMediaSelectProtocol;
import com.huawei.appgallery.common.media.api.IMediaSelectResult;
import com.huawei.appgallery.common.media.api.OriginalMediaBean;
import com.huawei.appgallery.forum.option.api.IUpdateCommentActivityProtocol;
import com.huawei.appgallery.forum.option.api.IUpdateCommentActivityResult;
import com.huawei.appgallery.forum.option.comment.bean.UpdateCommentRes;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.hmf.annotation.ActivityDefine;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.blc;
import o.bqx;
import o.bqy;
import o.brc;
import o.brd;
import o.bse;
import o.bsx;
import o.btu;
import o.bya;
import o.byc.c;
import o.byc.d;
import o.byc.e;
import o.byc.f;
import o.byc.j;
import o.byg;
import o.byk;
import o.byl;
import o.byz;
import o.PermissionChecker;
import o.cgv;
import o.dnw;
import o.CollectCheck;
import o.evk;
import o.evx;
import o.fho;
import o.fiu;
import o.fiv;
import o.fjb;
import o.fjc;
import o.fjf;
import o.fjo;
import o.fjq;

@ActivityDefine(alias = "option.update.comment", protocol = IUpdateCommentActivityProtocol.class, result = IUpdateCommentActivityResult.class)
public class UpdateCommentActivity extends AbstractBaseActivity implements OnClickListener, e {
    private ImageView ʻॱ;
    private byl ʽॱ;
    private UpdateCommentContentLayout ʾ;
    private boolean ʿ = false;
    private boolean ˈ = false;
    private Handler ˉ;
    private String ˊˊ;
    private ImageView ˊॱ;
    private fiv ˋॱ = fiv.ॱ(this);
    private byg ˏॱ;
    private ProgressBar ͺ;
    private ViewGroup ॱˊ;
    private boolean ॱˋ = false;
    private ViewGroup ॱˎ;
    private ViewGroup ᐝॱ;

    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        IUpdateCommentActivityProtocol iUpdateCommentActivityProtocol = (IUpdateCommentActivityProtocol) this.ˋॱ.ॱ();
        this.ˏॱ = iUpdateCommentActivityProtocol.getCommentData();
        this.ˊˊ = iUpdateCommentActivityProtocol.getDomainId();
        if (this.ˏॱ == null) {
            bqx.ॱ("UpdateCommentActivity", "commentData == null");
            finish();
            return;
        }
        setContentView(f.ʼ);
        ॱˊ();
        ᐝॱ();
        ʼॱ();
        ͺ();
    }

    private void ͺ() {
        this.ˉ = new Handler(this, Looper.getMainLooper()) {
            final /* synthetic */ UpdateCommentActivity ˋ;

            public void handleMessage(Message message) {
                if (message.what == 1) {
                    this.ˋ.ˏ(true);
                } else if (message.what == 0) {
                    this.ˋ.ˏ(false);
                } else {
                    bqx.ˊ("UpdateCommentActivity", "invalid msg");
                }
            }
        };
    }

    private void ॱˊ() {
        cgv.ˋ(this, e.ॱ, e.ʽ);
        View findViewById = findViewById(d.ʽॱ);
        azb.ˏ(findViewById);
        ((ViewGroup) findViewById.findViewById(d.ᐝ)).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ UpdateCommentActivity ˋ;

            {
                this.ˋ = r1;
            }

            public void onClick(View view) {
                this.ˋ.finish();
            }
        });
        ((TextView) findViewById.findViewById(d.ˋˊ)).setText(j.ˊॱ);
        this.ॱˊ = (ViewGroup) findViewById.findViewById(d.ˋॱ);
        this.ॱˊ.setContentDescription(getString(j.ˊॱ));
        this.ॱˊ.setOnClickListener(new evx(this) {
            final /* synthetic */ UpdateCommentActivity ˊ;

            {
                this.ˊ = r1;
            }

            public void ˋ(View view) {
                this.ˊ.ˊˋ();
            }
        });
        this.ˊॱ = (ImageView) this.ॱˊ.findViewById(d.ͺ);
        this.ˊॱ.setImageResource(c.ˊ);
        this.ͺ = (ProgressBar) findViewById.findViewById(d.ʾ);
    }

    private void ᐝॱ() {
        this.ॱˎ = (ViewGroup) findViewById(d.ˊॱ);
        this.ॱˎ.setVisibility(8);
        this.ʻॱ = (ImageView) this.ॱˎ.findViewById(d.ॱˋ);
        this.ʻॱ.setOnClickListener(this);
        this.ᐝॱ = (ViewGroup) findViewById(d.ˏ);
        this.ᐝॱ.setVisibility(0);
        this.ॱˎ.setVisibility(8);
        ((ImageView) this.ᐝॱ.findViewById(d.ॱˋ)).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ UpdateCommentActivity ॱ;

            {
                this.ॱ = r1;
            }

            public void onClick(View view) {
                if (!PermissionChecker.ˋ(this.ॱ, 16)) {
                    this.ॱ.ˊˊ();
                }
            }
        });
        this.ॱˎ.findViewById(d.ˉ).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ UpdateCommentActivity ˏ;

            {
                this.ˏ = r1;
            }

            public void onClick(View view) {
                this.ˏ.ˉ();
            }
        });
        this.ʾ = (UpdateCommentContentLayout) findViewById(d.ˍ);
        this.ʾ.setContentChangeListener(this);
    }

    private void ʼॱ() {
        if (!TextUtils.isEmpty(this.ˏॱ.ˊ())) {
            this.ʾ.setText(this.ˏॱ.ˊ().replace("[br]", "\n"));
        }
        ˋ(this.ˏॱ.ॱ());
    }

    private void ˋ(byl o_byl) {
        if (o_byl == null) {
            bqx.ˊ("UpdateCommentActivity", "uploadImageData == null");
            return;
        }
        this.ʽॱ = o_byl;
        this.ˏॱ.ˋ(this.ʽॱ);
        this.ʿ = true;
        this.ᐝॱ.setVisibility(8);
        this.ॱˎ.setVisibility(0);
        ˊᐝ();
        if (o_byl.ʼ()) {
            bsx.ॱ(this.ʻॱ, o_byl.ˏ());
            ॱ(o_byl);
            return;
        }
        bsx.ॱ(this.ʻॱ, o_byl.ʽ());
    }

    private void ॱ(byl o_byl) {
        if (o_byl.ॱॱ() != 2) {
            ((bya) fho.ˏ().ˋ("Option").ॱ(bya.class)).ˎ(this.ˊˊ, o_byl, this.ˏॱ.ˋ()).ˏ(new fjq<byl>(this) {
                final /* synthetic */ UpdateCommentActivity ˎ;

                {
                    this.ˎ = r1;
                }

                public void onComplete(fjo<byl> o_fjo_o_byl) {
                    if (o_fjo_o_byl.ˊ() && this.ˎ.ॱˋ) {
                        byl o_byl = (byl) o_fjo_o_byl.ॱ();
                        if (o_byl != null && !TextUtils.isEmpty(o_byl.ˋ()) && o_byl.ˋ().equals(this.ˎ.ʽॱ.ˋ())) {
                            if (o_byl.ॱॱ() == 2) {
                                this.ˎ.ˋˊ();
                                return;
                            }
                            bqx.ॱ("UpdateCommentActivity", "upload image failed");
                            evk.ˏ(this.ˎ.getString(j.ᐝ));
                            this.ˎ.ˊ(false);
                        }
                    }
                }
            });
        }
    }

    private void ˊˊ() {
        String[] strArr = new String[]{"image/jpeg", "image/jpg", "image/png", "image/webp", "image/gif", "image/bmp"};
        fjb ˎ = fho.ˏ().ˋ("Media").ˎ("MediaSelect");
        IMediaSelectProtocol iMediaSelectProtocol = (IMediaSelectProtocol) ˎ.ˊ();
        iMediaSelectProtocol.setMediaType("image");
        iMediaSelectProtocol.setMimeTyes(strArr);
        iMediaSelectProtocol.setMaxSelectSize(1);
        iMediaSelectProtocol.setMaxSelectFileSize(10485760);
        fiu.ˊ().ॱ((Context) this, ˎ, new fjc<IMediaSelectResult>(this) {
            final /* synthetic */ UpdateCommentActivity ॱ;

            {
                this.ॱ = r1;
            }

            public /* synthetic */ void ˎ(int i, Object obj) {
                ˋ(i, (IMediaSelectResult) obj);
            }

            public void ˋ(int i, IMediaSelectResult iMediaSelectResult) {
                if (ˊ() instanceof UpdateCommentActivity) {
                    ((UpdateCommentActivity) ˊ()).ˎ(i, iMediaSelectResult);
                }
            }
        });
    }

    private void ˎ(int i, IMediaSelectResult iMediaSelectResult) {
        if (i == -1 && iMediaSelectResult != null) {
            try {
                List selectedMedias = iMediaSelectResult.getSelectedMedias();
                if (!CollectCheck.isEmpty(selectedMedias)) {
                    OriginalMediaBean originalMediaBean = (OriginalMediaBean) selectedMedias.get(0);
                    if (originalMediaBean != null) {
                        byl o_byl = new byl(originalMediaBean);
                        o_byl.ˏ(true);
                        ˋ(o_byl);
                    }
                }
            } catch (Exception e) {
                bqx.ॱ("UpdateCommentActivity", "cast error");
            }
        }
    }

    private void ˉ() {
        this.ॱˎ.setVisibility(8);
        this.ᐝॱ.setVisibility(0);
        this.ˏॱ.ˋ(null);
        this.ʿ = false;
        this.ʽॱ = null;
        ˊᐝ();
    }

    private void ˊᐝ() {
        if (this.ʿ || !TextUtils.isEmpty(this.ʾ.ॱ().getText().toString().trim())) {
            this.ॱˊ.setClickable(true);
            this.ˊॱ.setImageResource(c.ॱ);
            return;
        }
        this.ॱˊ.setClickable(false);
        this.ˊॱ.setImageResource(c.ˊ);
    }

    private void ˊˋ() {
        ˊ(true);
        ˋˊ();
    }

    private void ˋˊ() {
        if (ˋˋ()) {
            this.ˏॱ.ˋ(btu.ˏ(this.ʾ.ॱ()).toString());
            ((brc) fho.ˏ().ˋ("Base").ॱ(brc.class)).ˋ(new byk.d(this.ˏॱ, true).ॱ(this.ˊˊ).ˊ(), new brc.e<byk, UpdateCommentRes>(this) {
                final /* synthetic */ UpdateCommentActivity ॱ;

                {
                    this.ॱ = r1;
                }

                public /* synthetic */ void ˋ(Object obj, Object obj2) {
                    ˏ((byk) obj, (UpdateCommentRes) obj2);
                }

                public /* synthetic */ void ˏ(Object obj, Object obj2) {
                    ˊ((byk) obj, (UpdateCommentRes) obj2);
                }

                public void ˊ(byk o_byk, UpdateCommentRes updateCommentRes) {
                }

                public void ˏ(byk o_byk, UpdateCommentRes updateCommentRes) {
                    this.ॱ.ˊ(false);
                    if (updateCommentRes.getResponseCode() == 0 && updateCommentRes.getRtnCode_() == 0) {
                        this.ॱ.ˏॱ.ॱ(updateCommentRes.ˋ());
                        this.ॱ.ˈ = true;
                        brd.ॱ.ˏ(bqy.ˋ().ˎ(this.ॱ), this.ॱ.ˊˊ, String.valueOf(this.ॱ.ˏॱ.ˎ()), String.valueOf(this.ॱ.ˏॱ.ˋ()));
                        byz.ˋ(false, String.valueOf(this.ॱ.ˏॱ.ˋ()));
                        this.ॱ.finish();
                    } else if (updateCommentRes.getRtnCode_() == 3004) {
                        evk.ˏ(this.ॱ.getString(bse.ˏ.ˏ("edit", 3004)));
                    } else {
                        evk.ˏ(this.ॱ.getString(bse.ˏ.ॱ(updateCommentRes.getRtnCode_()).ˏ()));
                    }
                }
            });
        }
    }

    private boolean ˋˋ() {
        if (this.ʽॱ == null || this.ʽॱ.ॱॱ() == 2) {
            return true;
        }
        if (this.ʽॱ.ॱॱ() == 3) {
            ॱ(this.ʽॱ);
        }
        return false;
    }

    public void finish() {
        int i;
        bqx.ˏ("UpdateCommentActivity", "updateSuccess:" + this.ˈ);
        if (this.ˈ) {
            i = -1;
        } else {
            i = 0;
        }
        if (this.ˏॱ != null) {
            dnw.ˊ(new File(byz.ˎ(false, String.valueOf(this.ˏॱ.ˋ()))));
        }
        fjf ˊ = fjf.ˊ(this);
        ((IUpdateCommentActivityResult) ˊ.ॱ()).setUpdateCommentResult(this.ˏॱ);
        setResult(i, ˊ.ˊ());
        super.finish();
    }

    private void ˏ(boolean z) {
        boolean z2;
        int i = 8;
        boolean z3 = true;
        this.ॱˋ = z;
        this.ͺ.setVisibility(z ? 0 : 8);
        ViewGroup viewGroup = this.ॱˊ;
        if (!z) {
            i = 0;
        }
        viewGroup.setVisibility(i);
        UpdateCommentContentLayout updateCommentContentLayout = this.ʾ;
        if (z) {
            z2 = false;
        } else {
            z2 = true;
        }
        updateCommentContentLayout.setEnabled(z2);
        ViewGroup viewGroup2 = this.ᐝॱ;
        if (z) {
            z2 = false;
        } else {
            z2 = true;
        }
        viewGroup2.setClickable(z2);
        viewGroup = this.ॱˎ;
        if (z) {
            z3 = false;
        }
        viewGroup.setClickable(z3);
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        fiu.ˊ().ˎ(i, i2, intent);
    }

    private void ˊ(boolean z) {
        Message obtain = Message.obtain();
        obtain.what = z ? 1 : 0;
        if (this.ˉ != null) {
            this.ˉ.sendMessage(obtain);
        }
    }

    public void onClick(View view) {
        if (view.getId() == d.ॱˋ && this.ʽॱ != null) {
            String ˊ = this.ʽॱ.ʼ() ? this.ʽॱ.ˊ() : this.ʽॱ.ʽ();
            fjb ˎ = fho.ˏ().ˋ("Media").ˎ("ImagePreview");
            IImagePreviewProtocol iImagePreviewProtocol = (IImagePreviewProtocol) ˎ.ˊ();
            ArrayList arrayList = new ArrayList();
            blc o_blc = new blc();
            o_blc.ॱ(ˊ);
            o_blc.ॱ(this.ʽॱ.ͺ());
            o_blc.ˋ(this.ʽॱ.ॱˊ());
            o_blc.ˋ(this.ʽॱ.ʽ());
            arrayList.add(o_blc);
            iImagePreviewProtocol.setSavePath(Environment.getExternalStorageDirectory() + "/Pictures/" + getString(j.ॱॱ));
            iImagePreviewProtocol.setOffset(0);
            iImagePreviewProtocol.setImageBeans(arrayList);
            fiu.ˊ().ˏ(this, ˎ);
        }
    }

    public void ᐝ() {
        ˊᐝ();
    }

    public void onRequestPermissionsResult(int i, @NonNull String[] strArr, @NonNull int[] iArr) {
        super.onRequestPermissionsResult(i, strArr, iArr);
        if (i == 16 && iArr.length != 0 && iArr[0] == 0) {
            ˊˊ();
        }
    }
}
